package v1

import (
	"gin-vue-admin/global"
    "gin-vue-admin/model"
    "gin-vue-admin/model/request"
    "gin-vue-admin/model/response"
    "gin-vue-admin/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

// @Tags BillList
// @Summary 创建BillList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.BillList true "创建BillList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /billList/createBillList [post]
func CreateBillList(c *gin.Context) {
	var billList model.BillList
	_ = c.ShouldBindJSON(&billList)
	billList.BillOperator = getUserName(c)
	if err, _ := service.CreateBillList(billList); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// @Tags BillList
// @Summary 删除BillList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.BillList true "删除BillList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /billList/deleteBillList [delete]
func DeleteBillList(c *gin.Context) {
	var billList model.BillList
	_ = c.ShouldBindJSON(&billList)
	if err := service.DeleteBillList(billList); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// @Tags BillList
// @Summary 批量删除BillList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除BillList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /billList/deleteBillListByIds [delete]
func DeleteBillListByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := service.DeleteBillListByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// @Tags BillList
// @Summary 更新BillList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.BillList true "更新BillList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /billList/updateBillList [put]
func UpdateBillList(c *gin.Context) {
	var billList model.BillList
	_ = c.ShouldBindJSON(&billList)
	if err := service.UpdateBillList(billList); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// @Tags BillList
// @Summary 用id查询BillList
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.BillList true "用id查询BillList"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /billList/findBillList [get]
func FindBillList(c *gin.Context) {
	var billList model.BillList
	_ = c.ShouldBindQuery(&billList)
	if err, rebillList := service.GetBillList(billList.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"rebillList": rebillList}, c)
	}
}

// @Tags BillList
// @Summary 分页获取BillList列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.BillListSearch true "分页获取BillList列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /billList/getBillListList [get]
func GetBillListList(c *gin.Context) {
	var pageInfo request.BillListSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := service.GetBillListInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败", zap.Any("err", err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}

func ConfirmBill(c *gin.Context) {
	var pageInfo model.BillList
	_ = c.ShouldBindJSON(&pageInfo)
	referrer := getUserName(c)
	if err := service.ConfirmBill(pageInfo, referrer); err != nil {
		global.GVA_LOG.Error("确认失败", zap.Any("err", err))
		response.FailWithMessage("确认失败，权限不足", c)
	} else {
		response.OkWithMessage("确认成功", c)
	}
}
